package net.adst.ui.mainframe.tabs;

import net.adst.resources.Constants;
import net.adst.ui.mainframe.tabs.nanemTap.NanemPanel;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;

/**
 * Created with IntelliJ IDEA.
 * User: alekseipot
 * Date: 02.11.12
 * Time: 3:55
 * To change this template use File | Settings | File Templates.
 */
public class AdstTabPanel extends JTabbedPane {


    private static int index = 0;

    public AdstTabPanel() {
        addTabbedPane();
        setColors();
    }

    private void setColors() {
        setBackground(Constants.COLOR_LIGHT_BLUE);
        Component[] components = getComponents();
        for (Component comp : components) {
            Component[] panelComponents = ((Container) comp).getComponents();
            for (Component compPanel : panelComponents) {
                Component[] settingsIn = ((Container) compPanel).getComponents();
                for (Component settIn : settingsIn) {
                    Component[] settingsInIn = ((Container) settIn).getComponents();
                    for (Component settInIn : settingsInIn) {
                        if (!(settInIn instanceof JComboBox) && !(settInIn instanceof JTextField) && !(settInIn instanceof JViewport)) {
                            settInIn.setBackground(Constants.COLOR_DARK_BLUE);
                        }
                    }
                    if (!(settIn instanceof JComboBox) && !(settIn instanceof JTextField)) {
                        settIn.setBackground(Constants.COLOR_DARK_BLUE);
                    }
                }
                compPanel.setBackground(Constants.COLOR_DARK_BLUE);
            }
            comp.setBackground(Constants.COLOR_DARK_BLUE);
        }
    }

    /**
     * Adds tabs (Home, Favourite, Reports, Settings)
     */
    private void addTabbedPane() {
        addTab("нанемаемая техника",  new NanemPanel());
//        addTab("наша техника", new NanemPanel());

        addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                index = getSelectedIndex();
            }
        });
        setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    }

    public static int getIndex() {
        return index;
    }
}
